package group2assignone.ucm.administrator;

import group2assignone.dao.MyDAO;
import group2assignone.ucm.UCController;
import group2assignone.ucm.UCStartup;
import group2assignone.view.UITool;
import group2assignone.view.administrator.AdminMainView;

/**
 *public class UCDeleteManager implements UCController
 * this is the class for the delete manager use case
 * it recieves the administrator main view as a paramater and
 * deletes the selected manager from the database
 * @author group2
 */
public class UCDeleteManager implements UCController {

    private AdminMainView view;

    public UCDeleteManager(AdminMainView m_view) {
        view = m_view;
    }

    /**
     * Use Case: Admin main UI
     * Pre-Condition: Add new Manager UI
     * Post-Condition: UI is updated
     * 1. Customer delete manager button
     * 2. System deletes selected manager
     * 3. System returns to main admin view
     * 
     * 2a. No manager is selected, System displays error and prompts user to
     *      select a manager to delete
     */
    public void run() {

        if (view.getSelectedRow() >= 0) {  //if have selection

            String userName = view.getUserName();

            MyDAO coms = UCStartup.getInstance().getDAO();
            boolean worked = coms.sQLDeleteManager(userName);

            view.dispose();
            UCUIAdminMainView uc = new UCUIAdminMainView();
            uc.run();

        } else {
            UITool.displayError("Select a Manager to Delete!!!", view);
        }
    }
}


